#include "mainmenu.h"

MainMenu::MainMenu(QWidget *parent) : QMainWindow(parent)
{
    this->setStyleSheet("QMainWindow{background-image: url(:/pic/背景板.png);}");
    this->setFixedSize(640,430);
    ui_Init();
    connect_Init();
    data_init();
}

void MainMenu::ui_Init()
{

    //更新气体名字
    for(int i=0;i<6;i++)
        if(qstrlen(Sysset->Gas[i].gasname) != 0)
        {
            Gas_Selname[i] = Sysset->Gas[i].gasname;
        }

    QFont font;
     //设置文字大小
     font.setPointSize(16);
    for(int i=0;i<20;i++)//创建主屏幕显示的按键
    {
         theLabel[i] = new QLabel(this);
         theLabel[i]->setStyleSheet("QLabel{\
                                outline: 0px ;                            /* 去掉获取焦点时的虚线 */ \
                                border-radius: 6px;		                 /* 按钮边框的圆角设置 */\
                                border-style: outset;\
                                /* 按钮文本设置 */\
                                qproperty-alignment: 'AlignCenter| AlignCenter';			             /* 文本的位置 */\
                                font-size: 22px;\
                                color: #000012;			                 /* 文本颜色 */\
                           }"
          );
    }

    for(int i=0;i<10;i++)//创建主屏幕显示的按键
    {
         focusBtn1[i] = new QPushButton(this);
        //每个按键因为如果要设置不同的图标的话，要设置不同stylesheet
         focusBtn1[i]->setFixedSize(200,36);

    focusBtn1[i]->setStyleSheet("QPushButton{\
                           outline: 0px ;                            /* 去掉获取焦点时的虚线 */ \
                           background-color: rgb(0, 170, 255);	    /* 背景颜色 */\
                           border-radius: 6px;		                 /* 按钮边框的圆角设置 */\
                           border-style: outset;\
                           /* 按钮文本设置 */\
                           text-align:center ;			             /* 文本的位置 */\
                           font-size: 20px;\
                           color: #FFFFFF;			                 /* 文本颜色 */\
                      }"
    "QPushButton:focus{\
    outline: 0px ;                            /* 去掉获取焦点时的虚线 */ \
    background-color: rgb(255,125,25);	    /* 背景颜色 */\
    border-radius: 6px;		                 /* 按钮边框的圆角设置 */\
    border-style: outset;\
       /* 按钮文本设置 */\
    text-align: center;			             /* 文本的位置 */\
    font-size: 22px;\
    qproperty-iconSize: 20px 20px;			/* 设置图标大小*/\
    color: rgb(0, 0, 0);			                 /* 文本颜色 */\
    }"
    "QPushButton:pressed{background-color:rgb(99,211,133);}"
    "QPushButton:hover{background-color:rgb(255,127,39);}"
    );
btnlist_ui.append(focusBtn1[i]);

}

QGridLayout *mainLayout = new QGridLayout();
for(int i=0;i<3;i++)
{
    mainLayout->addWidget(theLabel[i],1, i);
    mainLayout->addWidget(theLabel[3+i], 2, i);
    mainLayout->addWidget(theLabel[3*2+i], 3, i);
    mainLayout->addWidget(theLabel[3*3+i], 4, i);
}
mainLayout->setContentsMargins(50,0,50,0);//(int left, int top, int right, int bottom)
mainLayout->setSizeConstraint(QLayout::SetMinimumSize);//布局显示效果
QWidget* widget = new QWidget(this);
widget->setGeometry(0,0,640,180);
widget->setLayout(mainLayout);

theLabel[13]->setText(tr("SCCM"));
theLabel[14]->setText(tr("PPM"));
theLabel[15]->setText(tr("臭氧发生器"));
theLabel[16]->setText(tr("未运行"));

theLabel[12]->hide();
theLabel[16]->hide();
theLabel[17]->hide();


focusBtn1[0]->setText(tr("气体选择"));
focusBtn1[1]->setText(tr("数据"));
focusBtn1[2]->setText(tr("跨度选择"));
focusBtn1[3]->setText(tr("数据"));
focusBtn1[4]->setText(tr("臭氧选择"));
focusBtn1[5]->setText(tr("数据"));
focusBtn1[6]->setText(tr("光度计选择"));
focusBtn1[7]->setText(tr("blank"));
focusBtn1[8]->setText(tr("确定"));
focusBtn1[9]->setText(tr("返回"));

QGridLayout *theLayout2 = new QGridLayout();
theLayout2->addWidget(btnlist_ui.at(0), 1, 0,1,2);
theLayout2->addWidget(btnlist_ui.at(1), 1, 4,1,2);
theLayout2->addWidget(btnlist_ui.at(2), 2, 0,1,2);
theLayout2->addWidget(btnlist_ui.at(3), 2, 4,1,2);
theLayout2->addWidget(btnlist_ui.at(4), 3, 0,1,2);
theLayout2->addWidget(btnlist_ui.at(5), 3, 4,1,2);
theLayout2->addWidget(btnlist_ui.at(6), 4, 0,1,2);
theLayout2->addWidget(btnlist_ui.at(7), 4, 3,1,2);
theLayout2->addWidget(btnlist_ui.at(8), 5, 0,1,2);
theLayout2->addWidget(btnlist_ui.at(9), 5, 4,1,2);
theLayout2->addWidget(theLabel[13], 1, 7);
theLayout2->addWidget(theLabel[14], 2, 7);
theLayout2->addWidget(theLabel[15], 3, 7);
btnlist_ui.at(7)->hide();

if((!O3_Show_Flag))
{
    //隐藏
    btnlist_ui.at(5)->hide();
    btnlist_ui.at(4)->hide();
    theLabel[15]->hide();

}
if(!Photometer_Flag)
{
    //隐藏
    btnlist_ui.at(6)->hide();

}

//theLayout->setVerticalSpacing(50);
//theLayout->setHorizontalSpacing(10);
theLayout2->setContentsMargins(20,200,0,0);//(int left, int top, int right, int bottom)
//theLayout->setColumnStretch(1,22);
theLayout2->setSizeConstraint(QLayout::SetMinimumSize);
  setLayout(theLayout2);

  QWidget* widget2 = new QWidget(this);
  widget2->setGeometry(0,0,640,390);
  widget2->setLayout(theLayout2);


foreach (QPushButton *btn, btnlist_ui) {
    btn->installEventFilter(this);
}
//ABC种类切换  Sysset->Sys_Gas_Sel  0：关闭  1-3:气体ABC
connect(btnlist_ui.at(0),&QPushButton::clicked,[=](){
     if(Sysset->Sys_Gas_Sel==0)
     {
         Sysset->Sys_Gas_Sel =1;
         Sysset->Sys_Span_sel = 8;//默认从零气开始
         focusBtn1[0]->setText(Gas_Selname[0]);//气体名称更新为气体A
         focusBtn1[1]->setText(QString::number(Sysset->Gas[0].zeroairflow,'f',0));   //右边对应数值
         focusBtn1[3]->setText("-----");
         focusBtn1[2]->setText(tr("零气"));      //显示零气
     }
     else if(Sysset->Sys_Gas_Sel >0 && Sysset->Sys_Gas_Sel < Sysset->Gas_Num)
     {
         Sysset->Sys_Gas_Sel ++;
          focusBtn1[0]->setText(Gas_Selname[Sysset->Sys_Gas_Sel-1]);//气体名称更新
         //当前为标气和手动，需要更新两个数据
        if(Sysset->Sys_Span_sel >0 && Sysset->Sys_Span_sel <= 7)
         {
              focusBtn1[1]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[Sysset->Sys_Span_sel-1],'f',0));   //右边对应数值
              focusBtn1[3]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1],'f',3));
         }
         //当前为零气，需要更新一个数据
         else if(Sysset->Sys_Span_sel ==8)
             focusBtn1[1]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].zeroairflow,'f',0));   //右边对应数值
     }
     else if(Sysset->Sys_Gas_Sel == Sysset->Gas_Num)
     {
         Sysset->Sys_Gas_Sel = 0;  //由气体C变成关闭
         Sysset->Sys_Span_sel = 0;
          focusBtn1[0]->setText(tr("关闭"));//气体名称更新
          focusBtn1[2]->setText(tr("关闭"));  //标气也要关掉
//         theLabel[16]->setText("OFF");
          focusBtn1[3]->setText("-----");//标气数据需要更新
         if(Sysset->Sys_Ozo_Sel != 0)
              focusBtn1[1]->setText(QString::number(Sysset->Ozo_ZeroAir));
         else
             focusBtn1[1]->setText("-----");//气体数据更新
     }
});

//标气种类切换  flag   0：关闭  1-6：标气  7：手动  8：零气
connect(btnlist_ui.at(2),&QPushButton::clicked,[=](){
    //首先当前不能是关闭状态
    if(Sysset->Sys_Gas_Sel != 0  && Sysset->Sys_Span_sel !=0)
    {
        //当前为标气切换到标气或手动
        if(Sysset->Sys_Span_sel > 0 &&  Sysset->Sys_Span_sel <7)
        {
            Sysset->Sys_Span_sel++;           //切换下一个
            if(Sysset->Sys_Span_sel==7)
               theLabel[14]->setText("SCCM");
            else
                theLabel[14]->setText("PPM");
            //focusBtn1[2]->setText(Stand_Selname[Sys_Span_Sel-1]);  //第二行名字更新
            if(Sysset->Sys_Span_sel<7)
                focusBtn1[2]->setText(tr("标气") + " "+QString::number(Sysset->Sys_Span_sel));
            else if(Sysset->Sys_Span_sel==7)
                focusBtn1[2]->setText(tr("手动"));
            else
                focusBtn1[2]->setText(tr("零气"));
            focusBtn1[1]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[Sysset->Sys_Span_sel-1],'f',0));   //右边对应数值
            focusBtn1[3]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1],'f',3));
        }
    //当前为手动切换到零气
    else if(Sysset->Sys_Span_sel == 7)
        {
            Sysset->Sys_Span_sel=8;
            theLabel[14]->setText("");
            //focusBtn1[2]->setText(Stand_Selname[Sys_Span_Sel-1]);  //第二行名字更新
            if(Sysset->Sys_Span_sel<7)
                focusBtn1[2]->setText(tr("标气") + " "+QString::number(Sysset->Sys_Span_sel));
            else if(Sysset->Sys_Span_sel==7)
                focusBtn1[2]->setText(tr("手动"));
            else
                focusBtn1[2]->setText(tr("零气"));
            focusBtn1[1]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].zeroairflow,'f',0));   //右边对应数值
            focusBtn1[3]->setText("-----");
        }
        //当前为零气切换到标气
   else if(Sysset->Sys_Span_sel == 8)
        {
             theLabel[14]->setText("PPM");
             //focusBtn1[2]->setText(Stand_Selname[0]);  //第二行名字更新
             focusBtn1[2]->setText(tr("标气")+" "+"1");
             focusBtn1[3]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[0],'f',3));   //第二行右边对应数值
             focusBtn1[1]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[0],'f',0));   //第一行右边对应数值
             Sysset->Sys_Span_sel = 1;
        }
    }
});

//臭氧数据切换  0->关闭  1～6  7->手动
connect(btnlist_ui.at(4),&QPushButton::clicked,[=](){
    if(O3_Show_Flag)
    {
    if(Sysset->Sys_Ozo_Sel <=6)
    {
        Sysset->Sys_Ozo_Sel++;
        if(Sysset->Sys_Ozo_Sel<=6)
            focusBtn1[4]->setText(tr("臭氧发生器") +" "+QString::number(Sysset->Sys_Ozo_Sel));
        else if(Sysset->Sys_Ozo_Sel == 7 )
            focusBtn1[4]->setText(tr("手动"));
        if(Sysset->Sys_Run[1]!=3)
        {
            focusBtn1[5]->setText(QString("%1").arg(Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]));
        }
        else
        {
            focusBtn1[5]->setText(QString("%1").arg(Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1]));

        }
        if(Sysset->Sys_Gas_Sel==0) focusBtn1[1]->setText(QString::number(Sysset->Ozo_ZeroAir));
    }
    else
    {
        Sysset->Sys_Ozo_Sel=0;
        focusBtn1[4]->setText(tr("臭氧发生器关闭"));
        focusBtn1[5]->setText("-----");
        if(Sysset->Sys_Gas_Sel==0) focusBtn1[1]->setText("-----");
    }
    }

});

//光度计数据切换  0->关闭  1～3
connect(btnlist_ui.at(6),&QPushButton::clicked,[=](){
    Sysset->Sys_Run[1]++;
    if(Sysset->Sys_Run[1] <=3)
    {
        switch (Sysset->Sys_Run[1])
        {
        case 0:
        {
            focusBtn1[6]->setText(tr("光度计关闭"));
            theLabel[15]->setText("%");
            break;
        }
        case 1:
        {
            focusBtn1[6]->setText(tr("光度计强度"));
            theLabel[15]->setText("%");

            break;
        }
        case 2:
        {
            focusBtn1[6]->setText(tr("光度计外部"));
            theLabel[15]->setText("%");
            break;
        }
        case 3:
        {
            focusBtn1[6]->setText(tr("光度计控制"));
            theLabel[15]->setText("PPM");
            if(Sysset->Sys_Ozo_Sel!=0)
                focusBtn1[5]->setText(QString("%1").arg(Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1]));
            else
                focusBtn1[5]->setText("-----");
            break;
        }
        default:
            break;
        }
    }
    else
    {
        Sysset->Sys_Run[1]=0;
        focusBtn1[6]->setText(tr("光度计关闭"));
        theLabel[15]->setText("%");
        if(Sysset->Sys_Ozo_Sel!=0)
            focusBtn1[5]->setText(QString("%1").arg(Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]));
        else
            focusBtn1[5]->setText("-----");

    }
    if(Sysset->Sys_Run[1]!=3 &&Sysset->Sys_Ozo_Sel!=0)
    {
        focusBtn1[5]->setText(QString("%1").arg(Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]));
    }
    else if(Sysset->Sys_Run[1]==3 &&Sysset->Sys_Ozo_Sel!=0)
    {
        focusBtn1[5]->setText(QString("%1").arg(Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1]));

    }
});

//确定
connect(btnlist_ui.at(8),&QPushButton::clicked,[=](){

    Sysctrl->Sys_Gas_Sel = Sysset->Sys_Gas_Sel  = Sysset->Sys_Gas_Sel;
    //显示正在运行气体名字
    if(Sysset->Sys_Span_sel == 0 && Sysset->Sys_Ozo_Sel ==0)
        theLabel[16]->setText("OFF");
    else if(Sysset->Sys_Span_sel == 0 && Sysset->Sys_Ozo_Sel !=0)
        theLabel[16]->setText(tr("零气"));
    else
    {
        if(Sysset->Sys_Span_sel<7)
            theLabel[16]->setText(tr("标气") + " "+QString::number(Sysset->Sys_Span_sel));
        else if(Sysset->Sys_Span_sel==7)
            theLabel[16]->setText(tr("手动"));
        else
            theLabel[16]->setText(tr("零气"));
    }

    //传递运行数据
    if(Sysset->Sys_Gas_Sel>=1)
    {
        Sysctrl->Air_Consentration  = Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration;//钢平气浓度
         //标气
         if(Sysset->Sys_Span_sel>0 && Sysset->Sys_Span_sel <7)
            {
                Sysctrl->Sys_Span_Sel = Sysset->Sys_Span_sel= Sysset->Sys_Span_sel;
                Sysctrl->Total_Flow = Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[Sysctrl->Sys_Span_Sel-1];
                Sysctrl->Target_Consentration = Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysctrl->Sys_Span_Sel-1];
            }
         //手动
         else if(Sysset->Sys_Span_sel == 7)
            {
                Sysctrl->Sys_Span_Sel = Sysset->Sys_Span_sel = Sysset->Sys_Span_sel;
                QString s=focusBtn1[1]->text();
                QString s2 = focusBtn1[3]->text();
                if((s.toFloat()<100.0)&&(s.toFloat()!=0))  //防止用户不设置零气就按确定
                {
                   focusBtn1[1]->setText("100");
                   Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[6] = 100;
                }
                else if(s.toFloat()==0)   //允许用户设置为0
                {
                   focusBtn1[1]->setText("0");
                   Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[6] = 0;
                }
                if(s2.toFloat()<1)//防止用户不设置标气就按确定
                {
                    focusBtn1[3]->setText("1");
                    Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[6] = 1;
                }
                Sysctrl->AirFlow = Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[6];
                Sysctrl->Zero_Flow = Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[6];
            }
            //零气
           else if(Sysset->Sys_Span_sel == 8)
          {
                Sysctrl->Sys_Span_Sel = Sysset->Sys_Span_sel = 8;
                Sysctrl->Zero_Flow = Sysset->Gas[Sysset->Sys_Gas_Sel-1].zeroairflow;
                Sysctrl->Total_Flow = Sysctrl->Zero_Flow;
                Sysctrl->Target_Consentration = 0;
          }
    }
    else if(Sysset->Sys_Ozo_Sel == 0)  //当前既不出标气也不出臭氧
    {
        Sysctrl->Sys_Gas_Sel = Sysset->Sys_Gas_Sel= 0;
        Sysctrl->Sys_Span_Sel =Sysset->Sys_Span_sel= 0;
        Sysctrl->Total_Flow = 0;
        Sysctrl->Target_Consentration = 0;
        focusBtn1[1]->setText("-----");
        Sysset->Sys_Mode = 0;

    }



    //实时显示气体浓度
    if(Sysctrl->Sys_Gas_Sel)
    {

        QString data_nd;
        float all_flow  = Sysstatus->MFC_Zero_PostCal *1000 + Sysstatus->MFC_Air_PostCal;
        double  den_data = Sysstatus->MFC_Air_PostCal/(all_flow) * Sysset->Gas[Sysctrl->Sys_Gas_Sel-1].gasconcentration;
        if(all_flow < 1) den_data=0;     //Test
        float test_temp = den_data*1000 - (int)(den_data*1000); //1000 isnot  range
        if(test_temp==0) //less 3
             data_nd=QString::number(den_data);
        else
             data_nd =QString::number(den_data,'f',4);
        if(data_nd.toFloat()>=0.002 && Sysstatus->MFC_Air_PostCal && Sysstatus->MFC_Zero_PostCal &&!Sysset->Sys_Only_Ozo)
        {
            gas_RN[1] = data_nd;
            gas_RN[0] = Sysset->Gas[Sysctrl->Sys_Gas_Sel-1].gasname;
            gas_RN[2] = "PPM";
        }
        else
        {
            //这种是单独运行臭氧情况
            if(Sysctrl->Sys_Span_Sel==8 && Sysctrl->Sys_Gas_Sel==1 && Sysset->Sys_Only_Ozo)
                gas_RN[0] = gas_RN[2] =gas_RN[1] = "";
            else
            {
                gas_RN[1] = "0";
                gas_RN[0] = Sysset->Gas[Sysctrl->Sys_Gas_Sel-1].gasname;
                gas_RN[2] = "PPM";
            }
        }
    }
    else
        gas_RN[0] = gas_RN[2] =gas_RN[1] = "";
    theLabel[3]->setText(gas_RN[0]);
    theLabel[4]->setText(gas_RN[1]);
    theLabel[5]->setText(gas_RN[2]);


    //臭氧
    if(Sysset->Sys_Ozo_Sel==0)
    {
        Sysctrl->Sys_Ozo_Sel=Sysset->Sys_Only_Ozo = 0;
        Sysset->IS_OZO_ENABLE = 0;
        Sysctrl->BD_Ozonator.Vot_Set = 0;
        theLabel[17]->setText("");
        O3_RN[0]=O3_RN[1]=O3_RN[2]="";
        theLabel[6]->setText(O3_RN[0]);
        theLabel[7]->setText(O3_RN[1]);
        theLabel[8]->setText(O3_RN[2]);
        if(Sysset->Sys_Gas_Sel == 0)
        {
            Sysctrl->Sys_Gas_Sel = Sysset->Sys_Gas_Sel= 0;
            Sysctrl->Sys_Span_Sel = Sysset->Sys_Span_sel= 0;
            Sysctrl->Total_Flow = 0;
            Sysctrl->Target_Consentration = 0;
        }

        if(Sysset->Sys_Run[1]==2) //外部
         {
            photo_flag=1;
             Sysctrl->PhotoMeter_Mode=Sysset->Sys_Run[1];
             Sysset->PHOT_ENABLE = 1;
             Sysctrl->BD_Interface.Fflag = 0;//阀门控制切换标志 0:出来的时候为0  1:进去的时候为1
             Sysctrl->BD_Photometer.Vot_Set = Sysset->Phot_Span *0.132+5.7 ;
             theLabel[12]->setText(tr("光度计外部") );
             if(Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]==0)
                 Sysctrl->BD_Ozonator.Vot_Set = 0.00;
         }
        else if(Sysset->Sys_Run[1]!=2)
        {
            Sysset->Sys_Run[1]=0;
            Sysctrl->PhotoMeter_Mode=Sysset->Sys_Run[1];
            Sysctrl->BD_Interface.Fflag = 1;//阀门控制切换标志 0:出来的时候为0  1:进去的时候为1
            Sysctrl->BD_Photometer.Vot_Set =0;
            Sysctrl->BD_Ozonator.Vot_Set = Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]*0.132+5.7;
            Sysset->PHOT_ENABLE = 0;
            focusBtn1[6]->setText(tr("光度计关闭"));
            theLabel[15]->setText("%");
            Photometer_RN[0]=Photometer_RN[1]=Photometer_RN[2]="";
            theLabel[9]->setText(Photometer_RN[0]);
            theLabel[10]->setText(Photometer_RN[1]);
            theLabel[11]->setText(Photometer_RN[2]);
            theLabel[12]->setText(tr(" ") );
            photo_flag=0;
            if(Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]==0)
                Sysctrl->BD_Ozonator.Vot_Set = 0.00;
        }

    }


    else if(Sysset->Sys_Run[1]!=3) //当光度计还未为控制时
    {
        Sysctrl->PhotoMeter_Mode=Sysset->Sys_Run[1];
        Sysset->IS_OZO_ENABLE = 1;
        if(Sysset->Sys_Run[1]==0)
        {
            Sysset->PHOT_ENABLE = 0;
            Sysctrl->BD_Photometer.Vot_Set =0;
            Sysctrl->BD_Ozonator.Vot_Set = Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]*0.132+5.7;
            Sysctrl->BD_Interface.Fflag = 1;//阀门控制切换标志 0:出来的时候为0  1:进去的时候为1
            focusBtn1[6]->setText(tr("光度计关闭"));
            theLabel[15]->setText("%");
            theLabel[17]->setText("");
            Photometer_RN[0]=Photometer_RN[1]=Photometer_RN[2]="";
            theLabel[9]->setText(Photometer_RN[0]);
            theLabel[10]->setText(Photometer_RN[1]);
            theLabel[11]->setText(Photometer_RN[2]);
            theLabel[12]->setText(tr(" ") );
            photo_flag=0;
            if(Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]==0)
                Sysctrl->BD_Ozonator.Vot_Set = 0.00;
        }
        else
        {
            Sysset->PHOT_ENABLE = 1;
            Sysctrl->BD_Ozonator.Vot_Set = Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]*0.132+5.7;
            Sysctrl->BD_Interface.Fflag = 0;//阀门控制切换标志 0:出来的时候为0  1:进去的时候为1
            Sysctrl->BD_Photometer.Vot_Set =   Sysset->Phot_Span *0.132+5.7 ;
            photo_flag=1;
            switch (Sysset->Sys_Run[1])
            {
            case 0:
            {
                theLabel[12]->setText(tr(" "));
                break;
            }
            case 1:
            {
                theLabel[12]->setText(tr("光度计强度"));

                break;
            }
            case 2:
            {
                theLabel[12]->setText(tr("光度计外部"));
                break;
            }
            case 3:
            {
                theLabel[12]->setText(tr("光度计控制"));

                break;
            }
            default:
                break;
            }
            if(Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]==0)
                Sysctrl->BD_Ozonator.Vot_Set = 0.00;
        }
        O3_RunData = Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1];
        if(Sysset->Sys_Ozo_Sel>=1 && Sysset->Sys_Ozo_Sel <= 6)
            theLabel[17]->setText(tr("臭氧发生器") +" "+QString::number(Sysset->Sys_Ozo_Sel));
        else if(Sysset->Sys_Ozo_Sel == 0 )
            theLabel[17]->setText(tr("臭氧发生器关闭"));
        else if(Sysset->Sys_Ozo_Sel ==7)
            theLabel[17]->setText(tr("手动"));
        Sysctrl->Sys_Ozo_Sel =Sysset->Sys_Ozo_Sel= Sysset->Sys_Ozo_Sel;

        if(Sysset->Sys_Gas_Sel==0)   //如果当前标气选择关闭，只出臭氧
        {
            Sysset->Sys_Only_Ozo=1;  //是单独运行臭氧
//                Sysctrl->Sys_Gas_Sel=Sysset->Sys_Gas_Sel=1;
            Sysctrl->Sys_Span_Sel=Sysset->Sys_Span_sel=8;
            Sysctrl->Total_Flow = Sysset->Ozo_ZeroAir;
            Sysctrl->Target_Consentration=0;
            focusBtn1[1]->setText(QString("%1").arg(Sysset->Ozo_ZeroAir));
        }
        else
            Sysset->Sys_Only_Ozo =0; //不是单独运行臭氧
        if(Sysset->Sys_Ozo_Sel>=1 && Sysset->Sys_Ozo_Sel <= 6)
            O3_RN[0] =tr("臭氧发生器") +" "+QString::number(Sysset->Sys_Ozo_Sel);
        else if(Sysset->Sys_Ozo_Sel ==7)
            O3_RN[0] =tr("手动");
        O3_RN[1]=QString("%1").arg(O3_RunData);
        O3_RN[2]="%";
        if(!Sysset->Sys_Run[1])
        {
            Sysctrl->PhotoMeter_Mode=Sysset->Sys_Run[1];
            Sysctrl->BD_Interface.Fflag = 1;//阀门控制切换标志 0:出来的时候为0  1:进去的时候为1
            Sysctrl->BD_Photometer.Vot_Set =0;
            Sysctrl->BD_Ozonator.Vot_Set = Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]*0.132+5.7;
            Sysset->PHOT_ENABLE = 0;
            focusBtn1[6]->setText(tr("光度计关闭"));
            focusBtn1[5]->setText("%");
            Photometer_RN[0]=Photometer_RN[1]=Photometer_RN[2]="";
            theLabel[9]->setText(Photometer_RN[0]);
            theLabel[10]->setText(Photometer_RN[1]);
            theLabel[11]->setText(Photometer_RN[2]);
            theLabel[12]->setText(tr(" "));
            photo_flag=0;
            if(Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]==0)
                Sysctrl->BD_Ozonator.Vot_Set = 0.00;
        }
    }
    else if(Sysset->Sys_Run[1]==3) //当光度计为控制时
    {                photo_flag=1;
        theLabel[12]->setText(tr("光度计控制"));
        Sysctrl->PhotoMeter_Mode=Sysset->Sys_Run[1];
        Sysset->IS_OZO_ENABLE = 1; //其中totalflow_span代表当前总浓度
        Sysset->PHOT_ENABLE = 1;//光度计使能
        Sysctrl->BD_Interface.Fflag = 0;//阀门控制切换标志 0:出来的时候为0  1:进去的时候为1
        Sysctrl->BD_Photometer.Vot_Set = Sysset->Phot_Span *0.132+5.7 ;
        if(Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1]==0)
            Sysctrl->BD_Ozonator.Vot_Set = 0.00;
        else
            Sysctrl->BD_Ozonator.Vot_Set = (0.00065 * Sysset->Ozo_ZeroAir +0.2) * Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1] + 6.64 ;      //电压与设置浓度的线性关系

        if(Sysctrl->BD_Ozonator.Vot_Set>20.0)
            Sysctrl->BD_Ozonator.Vot_Set = 20.0;
        if(Sysctrl->BD_Ozonator.Vot_Set<0)
            Sysctrl->BD_Ozonator.Vot_Set = 0;

        O3_RunData = Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1];
        if(Sysset->Sys_Ozo_Sel>=1 && Sysset->Sys_Ozo_Sel <= 6)
            theLabel[17]->setText(tr("臭氧发生器") +" "+QString::number(Sysset->Sys_Ozo_Sel));
        else if(Sysset->Sys_Ozo_Sel == 0 )
            theLabel[17]->setText(tr("臭氧发生器关闭"));
        else if(Sysset->Sys_Ozo_Sel ==7)
            theLabel[17]->setText(tr("手动"));
        Sysctrl->Sys_Ozo_Sel =Sysset->Sys_Ozo_Sel= Sysset->Sys_Ozo_Sel;
        if(Sysset->Sys_Gas_Sel==0)   //如果当前标气选择关闭，只出臭氧
        {
            Sysset->Sys_Only_Ozo = 1;  //是单独运行臭氧
            Sysctrl->Sys_Span_Sel=Sysset->Sys_Span_sel=8;
            Sysctrl->Total_Flow = Sysset->Ozo_ZeroAir;
            if(Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1]==0)
            {
                Sysctrl->BD_Ozonator.Vot_Set = 0.00;
            }
            else
            {
                Sysctrl->BD_Ozonator.Vot_Set = (0.00065 * Sysset->Ozo_ZeroAir +0.2) * Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1] + 6.64 ;      //电压与设置浓度的线性关系
                if(Sysctrl->BD_Ozonator.Vot_Set>20.0)
                    Sysctrl->BD_Ozonator.Vot_Set = 20.0;
                if(Sysctrl->BD_Ozonator.Vot_Set<0)
                    Sysctrl->BD_Ozonator.Vot_Set = 0;
            }
            Sysctrl->Target_Consentration=0;
            focusBtn1[1]->setText(QString("%1").arg(Sysset->Ozo_ZeroAir));
        }
       else
        Sysset->Sys_Only_Ozo = 0; //不是单独运行臭氧
    if(Sysset->Sys_Ozo_Sel>=1 && Sysset->Sys_Ozo_Sel <= 6)
        O3_RN[0] =tr("臭氧发生器") +" "+QString::number(Sysset->Sys_Ozo_Sel);
    else if(Sysset->Sys_Ozo_Sel ==7)
        O3_RN[0] =tr("手动");
    O3_RN[1]=QString("%1").arg(O3_RunData);
    O3_RN[2]="%";
    BD_Ozonator_Vot_Set=Sysctrl->BD_Ozonator.Vot_Set;

    }
    if(Sysctrl->PhotoMeter_Mode && flag_daojin)
    {
            if(Sysctrl->PhotoMeter_Mode==1||Sysctrl->PhotoMeter_Mode==2)
            {
                Photometer_RN[0]=tr("O3");
                Photometer_RN[1]=(QString::number(daoji)+"秒");
                Photometer_RN[2]="PPM";
            }
           else if(Sysctrl->PhotoMeter_Mode==3)
            {
                Photometer_RN[0]=tr("O3");
                Photometer_RN[1]=(QString::number(daoji)+"秒");
                Photometer_RN[2]="PPM";
                O3_RN[0] = O3_RN[1] = O3_RN[2] = "";
            theLabel[6]->setText(O3_RN[0]);
            theLabel[7]->setText(O3_RN[1]);
            theLabel[8]->setText(O3_RN[2]);
            }
            Photometer_Integral.clear();
    }
    else
        Photometer_RN[0] = Photometer_RN[1] = Photometer_RN[2] = "";
        Photometer_Integral.clear();
    theLabel[9]->setText(Photometer_RN[0]);
    theLabel[10]->setText(Photometer_RN[1]);
    theLabel[11]->setText(Photometer_RN[2]);
    //保存
    Sysctrl->Para_Save = 1;

    if(Sysctrl->PhotoMeter_Mode==3&& !flag_daojin)
    {
                Photometer_RN[0]=tr("O3");
                Photometer_RN[1]=QString::number(Sysctrl->Show_Ozo,'f',3);
                Photometer_RN[2]="PPM";
                O3_RN[0] = O3_RN[1] = O3_RN[2] = "";
            theLabel[6]->setText(O3_RN[0]);
            theLabel[7]->setText(O3_RN[1]);
            theLabel[8]->setText(O3_RN[2]);
            Photometer_Integral.clear();
    }


if(Sysctrl->PhotoMeter_Mode == 0)
{
    flag_daojin = 1;
    photo_flag=0;
    daoji=300;
    test_daoji=60;
}

});

//总流量数值设置
connect(btnlist_ui.at(1),&QPushButton::clicked,[=](){


    if((Sysset->Sys_Gas_Sel!=0 && !Sysset->Lock_Status)) //Not O3 Only
    {
            if(Sysset->Sys_Gas_Sel!=0 && Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration==0)
            {
                the_Waring_Tip=("请设置钢瓶浓度！");
                waring_Tip *menux = new waring_Tip(this);
                menux->show();
            }
            else
            {
                button_show = focusBtn1[1];
               keyPad *board = new keyPad(this);
                board->show();
               connect(board,&keyPad::changename2,this,&MainMenu::Recive_Gas_SelData);
               connect(board,&keyPad::destroyed,[=](){
                   btnlist_ui.at(1)->setFocus();
               });
             }
    }
   else if(Sysset->Sys_Gas_Sel==0 && Sysset->Sys_Ozo_Sel!=0) //O3 only
    {
            focusBtn1[1]->setText(QString::number(Sysset->Ozo_ZeroAir));
            button_show = focusBtn1[1];

            keyPad *board = new keyPad(this);
             board->show();
            connect(board,&keyPad::changename2,this,&MainMenu::Recive_Gas_SelData);
            connect(board,&keyPad::destroyed,[=](){
                btnlist_ui.at(1)->setFocus();
            });
    }
    Sysctrl->Para_Save = 1;

});

//标气浓度数值设置
connect(btnlist_ui.at(3),&QPushButton::clicked,[=](){
    if(Sysset->Sys_Gas_Sel && Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration==0)
    {
        the_Waring_Tip=("请设置钢瓶浓度！");
        waring_Tip *menux = new waring_Tip(this);
        menux->show();
    }
   else if(Sysset->Sys_Gas_Sel && (Sysset->Sys_Span_sel!=0 && Sysset->Sys_Span_sel != 8)/*&& !Sysset->Lock_Status && Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration !=0*/)
    {
    button_show = focusBtn1[3];
    keyPad *board = new keyPad(this);
     board->show();
    connect(board,&keyPad::changename2,this,&MainMenu::Recive_Gas_StandData);
    connect(board,&keyPad::destroyed,[=](){
        btnlist_ui.at(3)->setFocus();
    });

    }

    Sysctrl->Para_Save = 1;
});

//O3 数值设置
connect(focusBtn1[5],&QPushButton::clicked,[=](){
    if(O3_Show_Flag && !Sysset->Lock_Status)
    {
    if(Sysset->Sys_Ozo_Sel!=0)
    {
        button_show = focusBtn1[5];
        keyPad *board = new keyPad(this);
         board->show();
        connect(board,&keyPad::changename2,this,&MainMenu::Recive_O3data);
        connect(board,&keyPad::destroyed,[=](){
            btnlist_ui.at(5)->setFocus();
        });

    }
    }
    Sysctrl->Para_Save = 1;
});

//返回按钮
connect(focusBtn1[9],&QPushButton::clicked,[=](){
    this->parentWidget()->show();
    this->close();
});
}

void MainMenu::data_init()
{
    Sysctrl->GasFlow_Mode=Sysset->Sys_Mode= 1;
    Sysctrl->Para_Save=1;

    //实时显示气体浓度
    theLabel[0]->setText("总流量");
    theLabel[1]->setText(data_totalflow);
    theLabel[2]->setText("SCCM");
     theLabel[3]->setText(gas_RN[0]);
     theLabel[4]->setText(gas_RN[1]);
     theLabel[5]->setText(gas_RN[2]);

     theLabel[6]->setText(O3_RN[0]);
     theLabel[7]->setText(O3_RN[1]);
     theLabel[8]->setText(O3_RN[2]);
     theLabel[9]->setText(Photometer_RN[0]);
     theLabel[10]->setText(Photometer_RN[1]);
     theLabel[11]->setText(Photometer_RN[2]);
  //正在运行
    if(Sysctrl->Sys_Span_Sel > 0 && Sysctrl->Sys_Gas_Sel >0)
    {
        if(Sysctrl->Sys_Span_Sel<7)
             theLabel[16]->setText(tr("标气") + " "+ QString::number(Sysctrl->Sys_Span_Sel));
        else if(Sysctrl->Sys_Span_Sel==7)
             theLabel[16]->setText(tr("手动"));
        else
             theLabel[16]->setText(tr("零气"));
        // theLabel[16]->setText(Stand_Selname[Sysctrl->Sys_Span_Sel-1]);//显示正在运行标气或者其他名字
    }
    else
         theLabel[16]->setText("OFF");
    //正在运行的臭氧
        if(Sysctrl->Sys_Ozo_Sel>=1 && Sysctrl->Sys_Ozo_Sel <= 6)
            theLabel[17]->setText(tr("臭氧发生器") +" "+QString::number(Sysctrl->Sys_Ozo_Sel));
        else if(Sysctrl->Sys_Ozo_Sel == 0 )
            theLabel[17]->setText("");
        else if(Sysctrl->Sys_Ozo_Sel ==7)
            theLabel[17]->setText(tr("手动"));
   //正常配气和气象滴定
   if(Sysset->Sys_Gas_Sel && Sysset->Sys_Span_sel)
   {
       focusBtn1[0]->setText(Gas_Selname[Sysset->Sys_Gas_Sel-1]);//气体名字
       //focusBtn1[2]->setText(Stand_Selname[Sys_Span_Sel -1]);//第二行名字
       if(Sysset->Sys_Span_sel<7)
           focusBtn1[2]->setText(tr("标气") + " "+QString::number(Sysset->Sys_Span_sel));
       else if(Sysset->Sys_Span_sel==7)
       {
           focusBtn1[2]->setText(tr("手动"));
           theLabel[14]->setText("SCCM");
       }
       else
       {
           focusBtn1[2]->setText(tr("零气"));
           theLabel[14]->setText("");
       }
       if(Sysset->Sys_Span_sel <= 7)      //标气和手动
      {
           //第一行数据
             focusBtn1[1]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[Sysset->Sys_Span_sel-1],'f',0));
            //第二行数据
             focusBtn1[3]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1],'f',3));
       }
       else
       {
         focusBtn1[1]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].zeroairflow,'f',0));   //右边对应数值
         focusBtn1[3]->setText("0");
       }
   }
   else if(Sysset->Sys_Ozo_Sel!=0)
   {
       focusBtn1[1]->setText(QString("%1").arg(Sysset->Ozo_ZeroAir));
       focusBtn1[0]->setText(tr("关闭"));
       focusBtn1[2] ->setText(tr("关闭"));
       focusBtn1[3]->setText("-----");
   }
   else
   {
       focusBtn1[0]->setText(tr("关闭"));//气体名字
       focusBtn1[1]->setText("-----");   //右边对应数值
       focusBtn1[2] ->setText(tr("关闭"));
       focusBtn1[3]->setText("-----");
   }
    //臭氧数据初始化
   //focusBtn1[4]->setText(O3name[Sysset->Sys_Ozo_Sel]);  //显示上次退出时的臭氧数据
   if(Sysset->Sys_Ozo_Sel>=1 && Sysset->Sys_Ozo_Sel <= 6)
       focusBtn1[4]->setText(tr("臭氧发生器") +" "+QString::number(Sysset->Sys_Ozo_Sel));
   else if(Sysset->Sys_Ozo_Sel == 0 )
       focusBtn1[4]->setText(tr("臭氧发生器关闭"));
   else if(Sysset->Sys_Ozo_Sel ==7)
       focusBtn1[4]->setText(tr("手动"));
       if(Sysset->Sys_Ozo_Sel!=0)
           focusBtn1[5]->setText(QString("%1").arg(Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]));
       else
           focusBtn1[5]->setText("-----");
         theLabel[6]->setText(O3_RN[0]);
         theLabel[7]->setText(O3_RN[1]);
         theLabel[8]->setText(O3_RN[2]);
        Sysset->Sys_Run[1]=Sysctrl->PhotoMeter_Mode;
        switch (Sysset->Sys_Run[1])
        {
        case 0:
        {
            focusBtn1[6]->setText(tr("光度计关闭"));
            theLabel[15]->setText("%");
            theLabel[12]->setText(tr(" "));
            break;
        }
        case 1:
        {
            focusBtn1[6]->setText(tr("光度计强度"));
            theLabel[15]->setText("%");
            theLabel[12]->setText(tr("光度计强度"));
            break;
        }
        case 2:
        {
            focusBtn1[6]->setText(tr("光度计外部"));
            theLabel[15]->setText("%");
            theLabel[12]->setText(tr("光度计外部"));
            break;
        }
        case 3:
        {
            focusBtn1[6]->setText(tr("光度计控制"));
            theLabel[15]->setText("PPM");
            theLabel[12]->setText(tr("光度计控制"));
            if(Sysset->Sys_Ozo_Sel!=0)
                focusBtn1[5]->setText(QString("%1").arg(Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1]));
            else
                focusBtn1[5]->setText("-----");
            break;
        }
        default:
            break;
        }
}

void MainMenu::connect_Init()
{
    //定时器
    timer =new QTimer(this);
    timer->start(1000);

    //远程控制时实时显示数据的更新
    timer5 = new QTimer(this);
    timer5->start(500);

    connect(timer5,&QTimer::timeout,[=](){

        if(!timer5_Flag)
        {

            //正常配气和气象滴定
            if(Sysset->Sys_Gas_Sel>0)
            {
                focusBtn1[0]->setText(Gas_Selname[Sysset->Sys_Gas_Sel-1]);//气体名字
                if(Sysset->Sys_Span_sel>0&&Sysset->Sys_Span_sel<7)
                {
                    focusBtn1[2]->setText(tr("标气") + " "+QString::number(Sysset->Sys_Span_sel));
                    //第一行数据
                      focusBtn1[1]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[Sysset->Sys_Span_sel-1],'f',0));
                     //第二行数据
                      focusBtn1[3]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1],'f',3));
                }
                else if(Sysset->Sys_Span_sel==7)
                {
                    focusBtn1[2]->setText(tr("手动"));
                    theLabel[14]->setText("SCCM");
                    //第一行数据
                      focusBtn1[1]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[Sysset->Sys_Span_sel-1],'f',0));
                     //第二行数据
                      focusBtn1[3]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1],'f',3));
                }
                else if(Sysset->Sys_Span_sel==8)
                {
                    focusBtn1[2]->setText(tr("零气"));
                    theLabel[14]->setText("");
                    focusBtn1[1]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].zeroairflow,'f',0));   //右边对应数值
                    focusBtn1[3]->setText("-----");
                }
                else
                {
                    focusBtn1[1]->setText("-----");   //右边对应数值
                    focusBtn1[2] ->setText(tr("关闭"));
                    focusBtn1[3]->setText("-----");
                }

            }
            else if(Sysset->Sys_Ozo_Sel!=0)
            {
                focusBtn1[1]->setText(QString("%1").arg(Sysset->Ozo_ZeroAir));
                focusBtn1[0]->setText(tr("关闭"));
                focusBtn1[2] ->setText(tr("关闭"));
                focusBtn1[3]->setText("-----");
            }
            else
            {
                focusBtn1[0]->setText(tr("关闭"));//气体名字
                focusBtn1[1]->setText("-----");   //右边对应数值
                focusBtn1[2] ->setText(tr("关闭"));
                focusBtn1[3]->setText("-----");
            }


            if(Sysset->Sys_Gas_Sel != 0 && Sysset->Sys_Span_sel == 7)//手动
            {
                if(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1] >= Stand_set_Min.toFloat() && Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1] <=Stand_set_data.toFloat() )
                {
                        focusBtn1[3]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1],'f',3));
                }
                else if(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1] < Stand_set_Min.toFloat())
                {
                    Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1] = Stand_set_Min.toFloat();
                    focusBtn1[3]->setText(Stand_set_Min);
                }
                else if(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1] > Stand_set_data.toFloat())
                {
                    Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1] =Stand_set_data.toFloat();
                    focusBtn1[3]->setText(Stand_set_data);
                }
            }
             else if(Sysset->Sys_Gas_Sel != 0 && Sysset->Sys_Span_sel > 0&& Sysset->Sys_Span_sel < 7)//标气
                    {
                      //if(s2.toFloat() <0.002) s2="0.002";
                      //确定浓度可设置范围
                      StandMin = Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration *Stand_set_Min.toFloat()/(Stand_set_Min.toFloat()+ZERO_set_data.toFloat());
                      StandMax =Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration * Stand_set_data.toFloat()/(Stand_set_data.toFloat()+ZERO_set_Min.toFloat());
                      QString temp = QString::number(StandMin,'f',3);
                      QString temp2 = QString::number(StandMax,'f',3);
                        if(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1] >= StandMax)
                            Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1]= StandMax;
                        else if(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1] <= StandMin)
                            Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1]= StandMin;
                        float test_temp_2 = Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1]*1000;
                        float test_temp = Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1]*1000 - (int)(test_temp_2);
                        if(test_temp==0) //less 3
                            focusBtn1[3]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1],'f',3));
                        else
                            focusBtn1[3]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1],'f',3));
                        //确定新的总流量范围
                        float target_density = Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1]/Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration;
                        if(target_density != 0 && target_density <(Sysset->GasMFC_Range/(ZERO_set_data.toFloat()+ Sysset->GasMFC_Range)))
                        {
                             Min_totalflow = (Stand_set_Min.toFloat()/target_density);                  //总流量最小值
                             Max_totalflow = ZERO_set_data.toFloat()/(1-target_density);   //总流量最大值
                        }
                        else if(target_density != 0 && target_density >=(Sysset->GasMFC_Range/(ZERO_set_data.toFloat()+Sysset->GasMFC_Range)))
                        {
                            Min_totalflow =ZERO_set_Min.toFloat()/(1-target_density) ;      //总流量最小值
                            Max_totalflow =Sysset->GasMFC_Range/target_density;   //总流量最大值
                        }
                        else
                        {
                            Min_totalflow = 0;                  //此时目标浓度为0,总流量最小值即零气流量最小值
                            Max_totalflow =0;   //总流量最大值
                        }

              }
            Recive_Gas_SelData(focusBtn1[1]->text());


             //臭氧数据初始化
            if(Sysset->Sys_Ozo_Sel>=1 && Sysset->Sys_Ozo_Sel <= 6)
                theLabel[17]->setText(tr("臭氧发生器") +" "+QString::number(Sysset->Sys_Ozo_Sel));
            else if(Sysset->Sys_Ozo_Sel == 0)
                theLabel[17]->setText(tr("臭氧发生器关闭"));
            else if(Sysset->Sys_Ozo_Sel ==7)
                theLabel[17]->setText(tr("手动"));
                if(Sysset->Sys_Ozo_Sel!=0)
                    focusBtn1[5]->setText(QString("%1").arg(Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]));
                else
                    focusBtn1[5]->setText("-----");

                 switch (Sysset->Sys_Run[1])
                 {
                 case 0:
                 {
                     focusBtn1[6]->setText(tr("光度计关闭"));
                     theLabel[15]->setText("%");
                     break;
                 }
                 case 1:
                 {
                     focusBtn1[6]->setText(tr("光度计强度"));
                     theLabel[15]->setText("%");
                     break;
                 }
                 case 2:
                 {
                     focusBtn1[6]->setText(tr("光度计外部"));
                     theLabel[15]->setText("%");
                     break;
                 }
                 case 3:
                 {
                     focusBtn1[6]->setText(tr("光度计控制"));
                     theLabel[15]->setText("PPM");
                     theLabel[12]->setText(tr("光度计控制"));
                     if(Sysset->Sys_Ozo_Sel!=0)
                         focusBtn1[5]->setText(QString("%1").arg(Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1]));
                     else
                         focusBtn1[5]->setText("-----");
                     break;
                 }
                 default:
                     break;
                 }

            //关于远程协议控制时的状态栏的显示
//                 if(Sysset->Sys_Run[0])
                 {
                     //显示正在运行气体名字
                     //正在运行
                       if(Sysctrl->Sys_Span_Sel > 0)
                       {
                           if(Sysctrl->Sys_Span_Sel<7)
                               theLabel[16]->setText(tr("标气") + " "+ QString::number(Sysctrl->Sys_Span_Sel));
                           else if(Sysctrl->Sys_Span_Sel==7)
                               theLabel[16]->setText(tr("手动"));
                           else if(Sysctrl->Sys_Span_Sel==8)
                               theLabel[16]->setText(tr("零气"));
                           //theLabel[16]->setText(Stand_Selname[Sysctrl->Sys_Span_Sel-1]);//显示正在运行标气或者其他名字
                       }
                       else
                           theLabel[16]->setText("OFF");
                       //正在运行的臭氧
                           if(Sysctrl->Sys_Ozo_Sel>=1 && Sysctrl->Sys_Ozo_Sel <= 6)
                               theLabel[17]->setText(tr("臭氧发生器") +" "+QString::number(Sysctrl->Sys_Ozo_Sel));
                           else if(Sysctrl->Sys_Ozo_Sel == 0 )
                               theLabel[17]->setText("");
                           else if(Sysctrl->Sys_Ozo_Sel ==7)
                               theLabel[17]->setText(tr("手动"));

                           switch (Sysset->Sys_Run[1])
                           {
                           case 0:
                           {
                               focusBtn1[6]->setText(tr("光度计关闭"));
                               theLabel[15]->setText("%");
                               theLabel[12]->setText(tr(" "));
                               break;
                           }
                           case 1:
                           {
                               focusBtn1[6]->setText(tr("光度计强度"));
                               theLabel[15]->setText("%");
                               theLabel[12]->setText(tr("光度计强度"));
                               break;
                           }
                           case 2:
                           {
                               focusBtn1[6]->setText(tr("光度计外部"));
                               theLabel[15]->setText("%");
                               theLabel[12]->setText(tr("光度计外部"));
                               break;
                           }
                           case 3:
                           {
                               focusBtn1[6]->setText(tr("光度计控制"));
                               theLabel[15]->setText("PPM");
                               theLabel[12]->setText(tr("光度计控制"));
                               if(Sysset->Sys_Ozo_Sel!=0)
                                   focusBtn1[5]->setText(QString("%1").arg(Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1]));
                               else
                                   focusBtn1[5]->setText("-----");
                               break;
                           }
                           default:
                               break;
                           }
                 }

        }
    });

    connect(timer3,&QTimer::timeout,[=](){
        theLabel[19]->setText("");
        theLabel[18]->setText("");
        timer3->stop();
    });
    //时间实时更新
    connect(timer,&QTimer::timeout,[=](){

        theLabel[0]->setText("总流量");
        theLabel[1]->setText(data_totalflow);
        theLabel[2]->setText("SCCM");
        theLabel[3]->setText(gas_RN[0]);
        theLabel[4]->setText(gas_RN[1]);
        theLabel[5]->setText(gas_RN[2]);
        theLabel[6]->setText(O3_RN[0]);
        theLabel[7]->setText(O3_RN[1]);
        theLabel[8]->setText(O3_RN[2]);

        theLabel[9]->setText(Photometer_RN[0]);
        theLabel[10]->setText(Photometer_RN[1]);
        theLabel[11]->setText(Photometer_RN[2]);

    });

}
bool MainMenu::recive_data(QString s)

{
    s = QString::number(s.toFloat());
    btnlist_ui.at(1)->setText(s);
}

//接收数据
void MainMenu::Recive_Gas_SelData(QString s1)  //第一行的数据
{

    if(Sysset->Sys_Gas_Sel != 0)
    {
        if(Sysset->Sys_Span_sel != 8)//标气或者手动的数据
             {
                    if(Sysset->Sys_Span_sel == 7)//手动
                    {
                        Min_totalflow = ZERO_set_Min.toFloat();                  //零气流量最小值
                        Max_totalflow = ZERO_set_data.toFloat();   //零气流量最大值
                        if(s1.toFloat() >=Min_totalflow && s1.toFloat()<= Max_totalflow)
                        {
                            Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[6] = s1.toFloat();  //手动模式里总流量就是零气
                            focusBtn1[1]->setText(QString::number(s1.toFloat(),'f',0));
                        }
                        else if(s1.toFloat() < Min_totalflow)
                        {
                            Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[6] = 0;
                            focusBtn1[1]->setText(QString::number(0,'f',0));
                        }
                        else if(s1.toFloat() > Max_totalflow)
                        {
                            Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[6] = Max_totalflow;
                            focusBtn1[1]->setText(QString::number(Max_totalflow,'f',0));
                        }
                    }
                    else
                    {
                        if(Min_totalflow==0 || Max_totalflow ==0)  //首先要确定范围是有效值
                        {
                            //确定新的总流量范围
                            float target_density = Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1]/Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration;
                            if(target_density != 0 && target_density <(Sysset->GasMFC_Range/(ZERO_set_data.toFloat()+ Sysset->GasMFC_Range)))
                            {
                                 Min_totalflow = Stand_set_Min.toFloat()/target_density;                  //总流量最小值
                                 Max_totalflow = ZERO_set_data.toFloat()/(1-target_density);   //总流量最大值
                            }
                            else if(target_density != 0 && target_density >=(Sysset->GasMFC_Range/(ZERO_set_data.toFloat()+Sysset->GasMFC_Range)))
                            {
                                Min_totalflow =ZERO_set_Min.toFloat()/(1-target_density) ;                  //总流量最小值
                                Max_totalflow =Sysset->GasMFC_Range/target_density;   //总流量最大值
                            }
                            else
                            {
                                Min_totalflow = 0;   //此时目标浓度为0,总流量最小值即零气流量最小值
                                Max_totalflow =0;   //总流量最大值
                            }
                        }
                      if(s1.toFloat() <=Min_totalflow)
                         s1=QString::number(Min_totalflow,'f',3);
                      else if(s1.toFloat() >=Max_totalflow )
                          s1=QString::number(Max_totalflow,'f',3);
                       int temp_flowdata = s1.toFloat();
                      Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[Sysset->Sys_Span_sel-1] = temp_flowdata;
                      focusBtn1[1]->setText(QString::number(temp_flowdata,'f',0));
                    }

             }
       else if(Sysset->Sys_Span_sel == 8)  //零气的数据
             {
                if(s1.toFloat()<ZERO_set_Min.toFloat()) s1=ZERO_set_Min;
                if(s1.toFloat()>ZERO_set_data.toFloat()) s1= ZERO_set_data;
                int temp_flowzerodata = s1.toFloat();
                focusBtn1[1]->setText(QString::number(temp_flowzerodata));
                Sysset->Gas[Sysset->Sys_Gas_Sel-1].zeroairflow = s1.toFloat();
              }
     }
    else  if(Sysset->Sys_Ozo_Sel!= 0)//设置臭氧的零气数据
    {
        if(s1.toFloat()<100) s1=QString::number(100);
        if(s1.toFloat()>ZERO_set_data.toFloat()) s1= ZERO_set_data;
        int temp_O3_flow = s1.toFloat();
        focusBtn1[1]->setText(QString::number(temp_O3_flow));
        Sysset->Ozo_ZeroAir=temp_O3_flow;
    }
//    Sysctrl->Para_Save=1;
}

void MainMenu::Recive_Gas_StandData(QString s2)//第二行的数据包含手动和标气
{
    if(Sysset->Sys_Gas_Sel<1) return;
    s2 = QString::number(s2.toFloat());
    if(s2.toFloat() == 0)
    {
        focusBtn1[3]->setText(QString::number(Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1],'f',3));
        return;
    }
    if(Sysset->Sys_Gas_Sel != 0 && Sysset->Sys_Span_sel == 7)//手动
    {
        if(s2.toFloat() >= Stand_set_Min.toFloat() && s2.toFloat() <=Stand_set_data.toFloat() )
        {
                focusBtn1[3]->setText(QString::number(s2.toInt()));
                Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1] = s2.toInt();
        }
        else if(s2.toFloat() < Stand_set_Min.toFloat())
        {
            Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1] = Stand_set_Min.toFloat();
            focusBtn1[3]->setText(Stand_set_Min);
        }
        else if(s2.toFloat() > Stand_set_data.toFloat())
        {
            Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1] =Stand_set_data.toFloat();
            focusBtn1[3]->setText(Stand_set_data);
        }
    }
     else if(Sysset->Sys_Gas_Sel != 0 && Sysset->Sys_Span_sel != 8)//标气
            {
              //确定浓度可设置范围
              StandMin = Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration *Stand_set_Min.toFloat()/(Stand_set_Min.toFloat()+ZERO_set_data.toFloat());
              StandMax =Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration * Stand_set_data.toFloat()/(Stand_set_data.toFloat()+ZERO_set_Min.toFloat());
              QString temp = QString::number(StandMin,'f',3);
              QString temp2 = QString::number(StandMax,'f',3);
                if(s2.toFloat() >= StandMax)
                    s2= temp2;
                else if(s2.toFloat() <= StandMin)
                    s2= temp;
                Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1] = s2.toFloat();
                float test_temp2 = s2.toFloat()*1000;
                float test_temp = s2.toFloat()*1000 - (int)(test_temp2);
                if(test_temp==0) //less 3
                    focusBtn1[3]->setText(QString::number(s2.toFloat(),'f',3));
                else
                    focusBtn1[3]->setText(QString::number(s2.toFloat(),'f',3));
                //确定新的总流量范围
                float target_density = Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration_span[Sysset->Sys_Span_sel-1]/Sysset->Gas[Sysset->Sys_Gas_Sel-1].gasconcentration;
                if(target_density != 0 && target_density <(Sysset->GasMFC_Range/(ZERO_set_data.toFloat()+ Sysset->GasMFC_Range)))
                {
                     Min_totalflow = Stand_set_Min.toFloat()/target_density;                  //总流量最小值
                     Max_totalflow = ZERO_set_data.toFloat()/(1-target_density);   //总流量最大值
                }
                else if(target_density != 0 && target_density >=(Sysset->GasMFC_Range/(ZERO_set_data.toFloat()+Sysset->GasMFC_Range)))
                {
                    Min_totalflow =ZERO_set_Min.toFloat()/(1-target_density) ;      //总流量最小值
                    Max_totalflow =Sysset->GasMFC_Range/target_density;   //总流量最大值
                }
                else
                {
                    Min_totalflow = 0;                  //此时目标浓度为0,总流量最小值即零气流量最小值
                    Max_totalflow =0;   //总流量最大值
                }
                Recive_Gas_SelData(QString("%1").arg(Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[Sysset->Sys_Span_sel-1]));
                int  temp_2 = Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[Sysset->Sys_Span_sel-1];
                Sysset->Gas[Sysset->Sys_Gas_Sel-1].totalflow_span[Sysset->Sys_Span_sel-1] = temp_2;
                focusBtn1[1]->setText(QString::number(temp_2));
            }
    Sysctrl->Para_Save=1;
}

void MainMenu::Recive_O3data(QString s3)
{
    QString temp = QString::number(s3.toFloat(),'f',2);
    float  O3_data = temp.toFloat();
    if(Sysset->Sys_Ozo_Sel !=0 && Sysset->Sys_Run[1] ==3)
    {
        Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1]=s3.toFloat();
        focusBtn1[5]->setText(QString::number(s3.toFloat()));

         if(O3_data >5)
        {
            Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1]=5;
            focusBtn1[5]->setText("5");
        }
         if(O3_data <0)
        {
            Sysset->Set_Ozo_Con[Sysset->Sys_Ozo_Sel-1]=0;
            focusBtn1[5]->setText("0");
        }

    }
    else
    {
        if(Sysset->Sys_Ozo_Sel !=0 && O3_data<=100 &&  O3_data>=0)
        {
            Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]=s3.toFloat();
            focusBtn1[5]->setText(QString::number(s3.toFloat()));
        }
        else if(Sysset->Sys_Ozo_Sel !=0 && O3_data >100)
        {
            Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]=100;
            focusBtn1[5]->setText("100");
        }
        else if(Sysset->Sys_Ozo_Sel !=0 && O3_data <0)
        {
            Sysset->Ozo_Span[Sysset->Sys_Ozo_Sel-1]=0;
            focusBtn1[5]->setText("0");
        }
    }
    Sysctrl->Para_Save=1;
}


void MainMenu::Recive_Photo_data(QString s4)
{
    QString temp = QString::number(s4.toFloat(),'f',2);
    float  temp_data = temp.toFloat();
Sysctrl->BD_Ozonator.Vot_Set =temp_data;
            focusBtn1[7]->setText(temp);

    Sysctrl->Para_Save=1;
}

bool MainMenu::eventFilter(QObject *watched, QEvent *event)
{

        for(int i=0;i<btnlist_ui.length();i++)
            if(btnlist_ui.at(i) == watched)
        {
            if(event->type() == QEvent::KeyPress)
            {
               QKeyEvent *ev = (QKeyEvent *)event;
               QPushButton *button = (QPushButton *)watched;
               switch (ev->key())
               {
               case OK:
                 {
                   emit  button->clicked();
                   break;
                 }
               case UP://上
               {

                   if(focusWidget() == btnlist_ui.at(9))
                   {
                                     focusPreviousChild();
                                     focusPreviousChild();
                                     focusPreviousChild();
                   }
                   else if(focusWidget() == btnlist_ui.at(8))
                   {
                       focusPreviousChild();
                   }
                   else if(focusWidget() != btnlist_ui.first())
                   {
                       focusPreviousChild();
                       focusPreviousChild();
                   }
                   break;
               }
               case DOWN://下
               {
                   if(focusWidget() == btnlist_ui.at(5))
                   {
                       focusNextChild();
                       focusNextChild();
                       focusNextChild();
                   }
                   else if(focusWidget() == btnlist_ui.at(6))
                   {
                       focusNextChild();
                   }
                   else if(focusWidget() != btnlist_ui.back())
                   {
                       focusNextChild();
                       focusNextChild();
                   }
                   break;
               }
               case LEFT://左
               {
                 if(focusWidget() != btnlist_ui.first())
                      focusPreviousChild();
                 break;
               }
               case RIGHT://右
               {
                 if(focusWidget() != btnlist_ui.back())
                      focusNextChild();
              break;
               }
               default:
                   break;
               }
            }

            }
}

